WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
frame_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Fwd refs
22namespace wolf
23{
24class TrajectoryBase;
25class CaptureBase;
26class StateBlock;
27} // namespace wolf
28
29// Wolf includes
30#include "core/common/wolf.h"
33
34namespace wolf
35{
36// class FrameBase
38{
39 friend CaptureBase;
40 friend FactorBase;
41
42 private:
43 TrajectoryBaseWPtr trajectory_ptr_;
44 CaptureBasePtrList capture_list_;
45
46 static unsigned int frame_id_count_;
47
48 protected:
49 unsigned int frame_id_;
51
52 public:
61 FrameBase(const TimeStamp& _ts,
62 const TypeComposite& _frame_types,
63 const VectorComposite& _frame_vectors,
64 const PriorComposite& _frame_priors = {});
65
66 ~FrameBase() override = default;
67
68 // Add and remove from WOLF tree ---------------------------------
69 template <typename classType, typename... T>
70 static std::shared_ptr<classType> emplace(TrajectoryBasePtr _ptr, T&&... all);
71
72 void link(TrajectoryBasePtr);
73 void link(ProblemPtr _prb);
74
75 void remove(bool viral_remove_parent_without_children = false) override;
76 bool hasChildren() const override;
77
78 // Frame properties -----------------------------------------------
79 public:
80 unsigned int id() const override;
81
82 // Frame values ------------------------------------------------
83 public:
84 void setTimeStamp(const TimeStamp& _ts);
85 TimeStamp getTimeStamp() const;
86 void getTimeStamp(TimeStamp& _ts) const;
87
88 // State blocks ----------------------------------------------------
89 public:
90 StateBlockConstPtr getV() const;
91 StateBlockPtr getV();
92
93 protected:
94 void setProblem(ProblemPtr _problem) override final;
95
96 // Wolf tree access ---------------------------------------------------
97 public:
98 TrajectoryBaseConstPtr getTrajectory() const;
99 TrajectoryBasePtr getTrajectory();
100
101 FrameBaseConstPtr getPreviousFrame(const unsigned int& i = 1) const;
102 FrameBaseConstPtr getNextFrame(const unsigned int& i = 1) const;
103 FrameBasePtr getPreviousFrame(const unsigned int& i = 1);
104 FrameBasePtr getNextFrame(const unsigned int& i = 1);
105
106 CaptureBaseConstPtrList getCaptureList() const;
107 CaptureBasePtrList getCaptureList();
108 bool hasCapture(const CaptureBaseConstPtr& _capture) const;
109
110 FactorBaseConstPtrList getFactorList() const;
111 FactorBasePtrList getFactorList();
112 void getFactorList(FactorBaseConstPtrList& _fac_list) const;
113 void getFactorList(FactorBasePtrList& _fac_list);
114
115 template <class C>
116 std::shared_ptr<const C> getCaptureOfType() const;
117 template <class C>
118 std::shared_ptr<C> getCaptureOfType();
119
120 CaptureBaseConstPtr getCaptureOfType(const std::string& type) const;
121 CaptureBasePtr getCaptureOfType(const std::string& type);
122
123 template <class C>
124 std::list<std::shared_ptr<const C>> getCapturesOfType() const;
125 template <class C>
126 std::list<std::shared_ptr<C>> getCapturesOfType();
127
128 CaptureBaseConstPtrList getCapturesOfType(const std::string& type) const;
129 CaptureBasePtrList getCapturesOfType(const std::string& type);
130
131 CaptureBaseConstPtr getCaptureOf(SensorBaseConstPtr _sensor_ptr) const;
132 CaptureBasePtr getCaptureOf(SensorBaseConstPtr _sensor_ptr);
133
134 CaptureBaseConstPtr getCaptureOf(SensorBaseConstPtr _sensor_ptr, const std::string& type) const;
135 CaptureBasePtr getCaptureOf(SensorBasePtr _sensor_ptr, const std::string& type);
136
137 CaptureBaseConstPtrList getCapturesOf(SensorBaseConstPtr _sensor_ptr) const;
138 CaptureBasePtrList getCapturesOf(SensorBasePtr _sensor_ptr);
139
140 // Debug and info -------------------------------------------------------
141 virtual void printHeader(int depth, //
142 bool factored_by, //
143 bool metric, //
144 bool state_blocks,
145 std::ostream& stream,
146 std::string _tabs = "") const;
147
148 void print(int depth, //
149 bool factored_by, //
150 bool metric, //
151 bool state_blocks,
152 std::ostream& stream = std::cout,
153 std::string _tabs = "") const;
154
155 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
156 bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
157
158 private:
159 CaptureBasePtr addCapture(CaptureBasePtr _capt_ptr);
160 void removeCapture(CaptureBasePtr _capt_ptr);
161 void setTrajectory(TrajectoryBasePtr _trj_ptr);
162
163 public:
165 {
166 return std::static_pointer_cast<FrameBase>(shared_from_this());
167 };
168 FrameBaseConstPtr shared_from_this_frame() const
169 {
170 return std::static_pointer_cast<const FrameBase>(shared_from_this());
171 };
172};
173
174} // namespace wolf
175
176// IMPLEMENTATION //
177
182
183namespace wolf
184{
185template <typename classType, typename... T>
186std::shared_ptr<classType> FrameBase::emplace(TrajectoryBasePtr _ptr, T&&... all)
187{
188 std::shared_ptr<classType> frm = std::make_shared<classType>(std::forward<T>(all)...);
189 frm->emplacePriors();
190 frm->link(_ptr);
191 return frm;
192}
193
194inline unsigned int FrameBase::id() const
195{
196 return frame_id_;
197}
198
199inline void FrameBase::getTimeStamp(TimeStamp& _ts) const
200{
201 _ts = time_stamp_;
202}
203
205{
206 return time_stamp_;
207}
208
209inline StateBlockConstPtr FrameBase::getV() const
210{
211 return getStateBlock('V');
212}
213
214inline StateBlockPtr FrameBase::getV()
215{
216 return getStateBlock('V');
217}
218
219inline TrajectoryBaseConstPtr FrameBase::getTrajectory() const
220{
221 return trajectory_ptr_.lock();
222}
223
224inline TrajectoryBasePtr FrameBase::getTrajectory()
225{
226 return trajectory_ptr_.lock();
227}
228
229inline CaptureBaseConstPtrList FrameBase::getCaptureList() const
230{
231 CaptureBaseConstPtrList list_const;
232 for (auto&& obj_ptr : capture_list_) list_const.push_back(obj_ptr);
233 return list_const;
234}
235
236inline CaptureBasePtrList FrameBase::getCaptureList()
237{
238 return capture_list_;
239}
240
241inline void FrameBase::setTrajectory(TrajectoryBasePtr _trj_ptr)
242{
243 trajectory_ptr_ = _trj_ptr;
244}
245
246template <class C>
247inline std::shared_ptr<const C> FrameBase::getCaptureOfType() const
248{
249 for (auto capture_ptr : getCaptureList())
250 {
251 auto cap_derived = std::dynamic_pointer_cast<const C>(capture_ptr);
252 if (cap_derived) return cap_derived;
253 }
254 return nullptr;
255}
256
257template <class C>
258inline std::shared_ptr<C> FrameBase::getCaptureOfType()
259{
260 for (auto capture_ptr : getCaptureList())
261 {
262 auto cap_derived = std::dynamic_pointer_cast<C>(capture_ptr);
263 if (cap_derived) return cap_derived;
264 }
265 return nullptr;
266}
267
268template <class C>
269inline std::list<std::shared_ptr<const C>> FrameBase::getCapturesOfType() const
270{
271 std::list<std::shared_ptr<const C>> captures;
272 for (auto capture_ptr : getCaptureList())
273 {
274 auto cap_derived = std::dynamic_pointer_cast<const C>(capture_ptr);
275 if (cap_derived) captures.push_back(cap_derived);
276 }
277 return captures;
278}
279
280template <class C>
281inline std::list<std::shared_ptr<C>> FrameBase::getCapturesOfType()
282{
283 std::list<std::shared_ptr<C>> captures;
284 for (auto capture_ptr : getCaptureList())
285 {
286 auto cap_derived = std::dynamic_pointer_cast<C>(capture_ptr);
287 if (cap_derived) captures.push_back(cap_derived);
288 }
289 return captures;
290}
291
292} // namespace wolf
Definition: capture_base.h:39
Definition: check_log.h:28
Definition: factor_base.h:72
Definition: frame_base.h:38
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Definition: frame_base.cpp:265
CaptureBaseConstPtrList getCapturesOf(SensorBaseConstPtr _sensor_ptr) const
Definition: frame_base.cpp:192
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Definition: frame_base.cpp:298
~FrameBase() override=default
bool hasCapture(const CaptureBaseConstPtr &_capture) const
Definition: frame_base.cpp:234
TimeStamp getTimeStamp() const
Definition: frame_base.h:204
unsigned int id() const override
Definition: frame_base.h:194
FactorBaseConstPtrList getFactorList() const
Definition: frame_base.cpp:208
void setTimeStamp(const TimeStamp &_ts)
Definition: frame_base.cpp:77
FrameBaseConstPtr getPreviousFrame(const unsigned int &i=1) const
Definition: frame_base.cpp:88
unsigned int frame_id_
Definition: frame_base.h:49
FrameBaseConstPtr shared_from_this_frame() const
Definition: frame_base.h:168
bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Definition: frame_base.cpp:340
std::list< std::shared_ptr< const C > > getCapturesOfType() const
Definition: frame_base.h:269
TimeStamp time_stamp_
frame time stamp
Definition: frame_base.h:50
CaptureBaseConstPtrList getCaptureList() const
Definition: frame_base.h:229
std::shared_ptr< const C > getCaptureOfType() const
Definition: frame_base.h:247
TrajectoryBaseConstPtr getTrajectory() const
Definition: frame_base.h:219
void link(TrajectoryBasePtr)
Definition: frame_base.cpp:239
void remove(bool viral_remove_parent_without_children=false) override
Definition: frame_base.cpp:43
FrameBasePtr shared_from_this_frame()
Definition: frame_base.h:164
void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Definition: frame_base.cpp:285
FrameBase(const TimeStamp &_ts, const TypeComposite &_frame_types, const VectorComposite &_frame_vectors, const PriorComposite &_frame_priors={})
Constructor time stamp and specs composite.
Definition: frame_base.cpp:32
StateBlockConstPtr getV() const
Definition: frame_base.h:209
FrameBaseConstPtr getNextFrame(const unsigned int &i=1) const
Definition: frame_base.cpp:102
void setProblem(ProblemPtr _problem) override final
Definition: frame_base.cpp:256
CaptureBaseConstPtr getCaptureOf(SensorBaseConstPtr _sensor_ptr) const
Definition: frame_base.cpp:176
static std::shared_ptr< classType > emplace(TrajectoryBasePtr _ptr, T &&... all)
Definition: frame_base.h:186
bool hasChildren() const override
Definition: frame_base.cpp:72
Definition: node_state_blocks.h:32
virtual StateBlockConstPtr getStateBlock(const char &_sb_key) const
Definition: node_state_blocks.h:275
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
Definition: vector_composite.h:27
Definition: capture_base.h:23